using System;
using System.Data;
using HRM.Common;

namespace HRM.BusinessLogic
{
    public class BhHeaderInfo : Standard_Info
    {
        public BhHeaderInfo()
        {
            _Document_Month = (Int32)Null.SetNullValue(_Document_Month);
            _Document_Year = (Int32)Null.SetNullValue(_Document_Year);
            _Document_Period = (Int32)Null.SetNullValue(_Document_Period);
            _Document_Social = (Decimal)Null.SetNullValue(_Document_Social);
            _Document_Medical = (Decimal)Null.SetNullValue(_Document_Medical);
            _Document_Unemployed = (Decimal)Null.SetNullValue(_Document_Unemployed);
            _Document_Basicsalary = (Decimal)Null.SetNullValue(_Document_Basicsalary);
            _Document_Totalemployeeold = (Int32)Null.SetNullValue(_Document_Totalemployeeold);
            _Document_Totalemployeenew = (Int32)Null.SetNullValue(_Document_Totalemployeenew);
            _Document_Totalsalaryold = (Decimal)Null.SetNullValue(_Document_Totalsalaryold);
            _Document_Totalsalarynew = (Decimal)Null.SetNullValue(_Document_Totalsalarynew);
            _Document_Totalunemployedold = (Int32)Null.SetNullValue(_Document_Totalunemployedold);
            _Document_Totalunemployednew = (Decimal)Null.SetNullValue(_Document_Totalunemployednew);
        }


        private Int64 _Document_Id;
        public Int64 Document_Id
        {
            get { return _Document_Id; }
            set { _Document_Id = value; }
        }

        private String _Document_Branchcode;
        public String Document_Branchcode
        {
            get { return _Document_Branchcode; }
            set { _Document_Branchcode = value; }
        }

        private DateTime _Document_Date;
        public DateTime Document_Date
        {
            get { return _Document_Date; }
            set { _Document_Date = value; }
        }

        private Int32 _Document_Month;
        public Int32 Document_Month
        {
            get { return _Document_Month; }
            set { _Document_Month = value; }
        }

        private Int32 _Document_Year;
        public Int32 Document_Year
        {
            get { return _Document_Year; }
            set { _Document_Year = value; }
        }

        private Int32 _Document_Period;
        public Int32 Document_Period
        {
            get { return _Document_Period; }
            set { _Document_Period = value; }
        }

        private Decimal _Document_Social;
        public Decimal Document_Social
        {
            get { return _Document_Social; }
            set { _Document_Social = value; }
        }

        private Decimal _Document_Medical;
        public Decimal Document_Medical
        {
            get { return _Document_Medical; }
            set { _Document_Medical = value; }
        }

        private Decimal _Document_Unemployed;
        public Decimal Document_Unemployed
        {
            get { return _Document_Unemployed; }
            set { _Document_Unemployed = value; }
        }

        private Decimal _Document_Basicsalary;
        public Decimal Document_Basicsalary
        {
            get { return _Document_Basicsalary; }
            set { _Document_Basicsalary = value; }
        }

        private Boolean _Document_Isinitial;
        public Boolean Document_Isinitial
        {
            get { return _Document_Isinitial; }
            set { _Document_Isinitial = value; }
        }

        private Int32 _Document_Totalemployeeold;
        public Int32 Document_Totalemployeeold
        {
            get { return _Document_Totalemployeeold; }
            set { _Document_Totalemployeeold = value; }
        }

        private Int32 _Document_Totalemployeenew;
        public Int32 Document_Totalemployeenew
        {
            get { return _Document_Totalemployeenew; }
            set { _Document_Totalemployeenew = value; }
        }

        private Decimal _Document_Totalsalaryold;
        public Decimal Document_Totalsalaryold
        {
            get { return _Document_Totalsalaryold; }
            set { _Document_Totalsalaryold = value; }
        }

        private Decimal _Document_Totalsalarynew;
        public Decimal Document_Totalsalarynew
        {
            get { return _Document_Totalsalarynew; }
            set { _Document_Totalsalarynew = value; }
        }

        private Int32 _Document_Totalunemployedold;
        public Int32 Document_Totalunemployedold
        {
            get { return _Document_Totalunemployedold; }
            set { _Document_Totalunemployedold = value; }
        }

        private Decimal _Document_Totalunemployednew;
        public Decimal Document_Totalunemployednew
        {
            get { return _Document_Totalunemployednew; }
            set { _Document_Totalunemployednew = value; }
        }

        private String _Document_Type;
        public String Document_Type
        {
            get { return _Document_Type; }
            set { _Document_Type = value; }
        }
    }


    public class BhHeader_Controller : Standard_Controller
    {
        #region "Contructor"
        private static BhHeader_Controller _instance;
        protected BhHeader_Controller() { }
        protected new void Dispose()
        {
            _instance = null;
        }
        private static object _syncLock = new object();
        public static BhHeader_Controller Instance()
        {
            if (_instance == null)
            {
                lock (_syncLock)
                {
                    if (_instance == null)
                        _instance = new BhHeader_Controller();
                }
            }
            return _instance;
        }
        public static BhHeader_Controller Instance(String transName)
        {
            if (!String.IsNullOrEmpty(transName))
            {
                BhHeader_Controller _instanceTrans = new BhHeader_Controller();
                _instanceTrans.Trans_Name = transName;
                return _instanceTrans;
            }
            else
                return Instance();
        }
        #endregion

        public const String cs_Table_Name = "HRM_BHHeader";

        public int Header_Using(int DocumentID)
        {
            return Globals.Object_GetValue<int>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_Using", false), DocumentID));
        }

        public DataSet Header_GetAll()
        {
            return DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_GetAll", false));
        }

        public DataSet Header_GetList(out int ItemCount, int currentPage, int pageSize, string _BranchCode, int _Month, int _Year, string _Type)
        {
            ItemCount = 0;
            DataSet ds = DataConnect.ExecuteDataset(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_GetList", false), _BranchCode, currentPage, pageSize, _Type, _Month, _Year);
            if (ds != null && ds.Tables.Count > 0)
                ItemCount = Globals.Object_GetValue<int>(ds.Tables[1].Rows[0][0]);
            return ds;
        }

        public BhHeaderInfo Header_GetInfo(int HeaderID)
        {
            return CBO.FillObject<BhHeaderInfo>(
                DataConnect.ExecuteRow(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_GetInfo", false), HeaderID)
                );
        }

        public BhHeaderInfo Header_GetMaxBymonth(int _Month, int _Year, string _BranchCode, string _Type)
        {
            return CBO.FillObject<BhHeaderInfo>(DataConnect.ExecuteRow(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_GetMaxByMonth", false), _Month, _Year, _BranchCode, _Type));
        }

        public int Header_Insert(BhHeaderInfo eInfo)
        {
            return Globals.Object_GetValue<int>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_Insert", false), eInfo.Document_Branchcode, eInfo.Document_Date, eInfo.Document_Month, eInfo.Document_Year, eInfo.Document_Period, eInfo.Document_Social, eInfo.Document_Medical, eInfo.Document_Unemployed, eInfo.Document_Basicsalary, eInfo.Document_Isinitial, eInfo.Document_Type));
        }

        public bool Header_Update(BhHeaderInfo eInfo)
        {
            return DataConnect.ExecuteNonQuery(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_Update", false), eInfo.Document_Id, eInfo.Document_Branchcode, eInfo.Document_Date, eInfo.Document_Month, eInfo.Document_Year, eInfo.Document_Period, eInfo.Document_Social, eInfo.Document_Medical, eInfo.Document_Unemployed, eInfo.Document_Basicsalary, eInfo.Document_Isinitial, eInfo.Document_Type) > 0;
        }

        public bool Header_Delete(int DocumentID)
        {
            return Globals.Object_GetValue<bool>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_Delete", false), DocumentID));
        }

        public bool Header_DeleteByPeriod(string BrandCode, int Year, int Month, int Period, string Type)
        {
            return Globals.Object_GetValue<bool>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_DeleteByPeriod", false), BrandCode, Year, Month, Period, Type));
        }

        public int Header_GetPreDocumentPeroid(string BrandCode, int Year, int Month, int Period, string Type)
        {
            return Globals.Object_GetValue<int>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_GetPreDocumentPeriod", false), BrandCode, Year, Month, Period, Type));
        }

        public bool Header_Exist(int _ID, string BranchCode, DateTime _Date, string _SIBookNo, string _FromDate, string _ToDate, string _InsTypeCode)
        {
            return Globals.Object_GetValue<bool>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_Exist", false), _ID, BranchCode, _Date, _SIBookNo, _FromDate, _ToDate, _InsTypeCode));
        }

        public bool Header_CheckExist(int _ID, string BranchCode, DateTime _Date, int _Month, int _Year, int _Period, string _Type)
        {
            return Globals.Object_GetValue<bool>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(cs_Table_Name, "HRM_Header_CheckExist", false), _ID, BranchCode, _Date, _Month, _Year, _Period, _Type));
        }
    }
}
